let editor = null;
$(document).ready(function () {
    window.parent.postMessage(['embed', {
        height: 500,
        slug: window.location.href.split('/').pop()
    }], '*');
    CodeMirror.modeURL = "/codemirror/mode/%N/%N.js"
    editor = CodeMirror.fromTextArea(document.getElementById("code"), {
        lineNumbers: true,
        matchBrackets: true,
        viewportMargin: Infinity
    });
    $.ajax({
        url: '/embed/snippet/' + window.location.href.split('/').pop(),
        type: 'get',
        dataType: 'JSON'
    }).done(d => {
        editor.setOption('mode', d.mode);
        CodeMirror.autoLoadMode(editor, d.mode);
        editor.doc.setValue(d.code);
        editor.doc.cantEdit = true;
    })
});